/**
 * @Author @fiber-cloud
 * @Date 2025/9/4 19:36
 */
public class ThreadDemo9 {
    //有三个线程，分别只能打印A,B,C,控制三个线程固定按照ABC的顺序来打印
    public static void main(String[] args) {

        Object locker1 = new Object();
        Object locker2 = new Object();


        Thread t1 = new Thread(()->{

            System.out.println("A");
            synchronized (locker1){
                locker1.notify();
            }

        });

        Thread t2 = new Thread(()->{
            synchronized (locker1){
                try {
                    locker1.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }

            System.out.println("B");
            synchronized (locker2){
                locker2.notify();
            }
        });

        Thread t3 = new Thread(()->{
            synchronized (locker2){
                try {
                    locker2.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }

            System.out.println("C");
        });

        t1.start();
        t2.start();
        t3.start();

    }

}
